/*
 * Filename ReporPermissionMapping.java 2022年09月06日
 * Copyright © Ehome Co.Ltd. All Rgiths Reserved.
 * @author wuyingchao
 */
package com.ehome.poct.backend.mapping;

import com.ehome.context.thread.UserThreadLocal;
import com.ehome.poct.core.api.constant.enums.ReportAnalysisType;
import com.ehome.poct.backend.api.vo.AddReportPermissionVO;
import com.ehome.poct.backend.api.vo.EditReportPermissionVO;
import com.ehome.poct.backend.api.vo.ProvinceInfoVO;
import com.ehome.poct.backend.api.vo.ReportAnalysisTypeVO;
import com.ehome.poct.core.api.dto.report.ConfAnalysisPermissionDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wyc
 * @since 2022/09/06 11:26
 **/
@Mapper(componentModel = "spring", imports = {UserThreadLocal.class, ProvinceInfoVO.class, Collectors.class})
public interface ReporPermissionMapping {

    @Mapping(target = "status", constant = "0")
    @Mapping(target = "lastOperator", expression = "java(UserThreadLocal.getUser().getName())")
    @Mapping(target = "provinceNames", expression = "java(add.getProvinces().stream().map(ProvinceInfoVO::getName).collect(Collectors.joining(\",\")))")
    @Mapping(target = "provinceCodes", expression = "java(add.getProvinces().stream().map(ProvinceInfoVO::getCode).collect(Collectors.joining(\",\")))")
    ConfAnalysisPermissionDTO to(AddReportPermissionVO add);

    @Mapping(target = "lastOperator", expression = "java(UserThreadLocal.getUser().getName())")
    @Mapping(target = "provinceNames", expression = "java(edit.getProvinces().stream().map(ProvinceInfoVO::getName).collect(Collectors.joining(\",\")))")
    @Mapping(target = "provinceCodes", expression = "java(edit.getProvinces().stream().map(ProvinceInfoVO::getCode).collect(Collectors.joining(\",\")))")
    ConfAnalysisPermissionDTO to(EditReportPermissionVO edit);

    List<ReportAnalysisTypeVO> to(List<ReportAnalysisType> typeEnums);

    @Mapping(target = "analysisName", source = "name")
    @Mapping(target = "analysisCode", source = "code")
    ReportAnalysisTypeVO to(ReportAnalysisType typeEnum);
}